package edu.tapestry.iddb.client.helpers;

import iddb.MessagePOJO;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PluginsMessages {

	Map<String, List<MessagePOJO>> messagesMap;
	
	
	public PluginsMessages(){
		this.messagesMap = new HashMap<String, List<MessagePOJO>>();
	}
	
	public void addMessage(MessagePOJO message){
		if (this.messagesMap.containsKey(message.getSender())){
			((List<MessagePOJO>)this.messagesMap.get(message.getSender())).add(message);
		}
		else{
			List<MessagePOJO> list = new ArrayList<MessagePOJO>();
			list.add(message);
			this.messagesMap.put(message.getSender(), list);
		}		
	}
	
	public void addMessage(List<MessagePOJO> messages){
		for (MessagePOJO pojo : messages){
			addMessage(pojo);
		}
	}
	
	public List<MessagePOJO> getMessages(String sender){
		if (!this.messagesMap.containsKey(sender)){
			return new ArrayList<MessagePOJO>();
		}
		return this.messagesMap.get(sender);
	}
}
